﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using RN.ERP.Web.ModelService;

namespace RN.ERP.Web.Enterprise
{
    public partial class EnterpriseInput : BasePage
    {
        private PersonService.PersonServiceClient personServiceClient = new PersonService.PersonServiceClient();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                GetParams();
            }
        }

        private void GetParams()
        {
            hdnClassID.Value = Request["classId"];
            Guid empGuid = Guid.Empty;
            Guid gid = Guid.Empty;
            if (!string.IsNullOrEmpty(Request.QueryString["empGuid"]))
            {
                if (Guid.TryParse(Request.QueryString["empGuid"], out empGuid))
                {
                    hdEmpGuid.Value = empGuid.ToString();
                }
            }
            if (!string.IsNullOrEmpty(Request.QueryString["gid"]))
            {
                if (Guid.TryParse(Request.QueryString["gid"], out gid))
                {
                    hdGid.Value = gid.ToString();
                    hdStatus.Value = "1";
                    var relation = JsonConvert.DeserializeObject<tb_User_Relation>(personServiceClient.GetUserRelationInfo(hdGid.Value, UserInfo.CurrentArea));
                    if (relation != null && relation.EntityGuid != null)
                    {
                        hdEntityGuid.Value = relation.EntityGuid.ToString();
                        hdEntityName.Value = relation.EntityName;
                        hdnClassID.Value = relation.ClassId.ToString();
                    }
                }
            }
            if (!string.IsNullOrEmpty(Request.QueryString["Flag"]))
            {
                hdFlag.Value = Request.QueryString["Flag"];
            }

        }

        public override bool IsCheckPermission
        {
            get { return false; }
        }
    }
}